package com.boruiimage.demo.mapperDao;

import com.boruiimage.demo.doMain.*;
import org.apache.ibatis.annotations.*;
import org.omg.PortableInterceptor.INACTIVE;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;

@Repository
@Mapper
public interface registerMapperDao {
    //如果该用户不是会员 充值会员
    @Insert("insert into memberuser (username,systemCount,personCount,data,memberCode,systemUseNum,personUseNum)value(#{userName},#{systemCount},#{personCount},now(),#{memberCode},0,0)")
    int addMemberUser(@Param(value = "userName")String userName,@Param(value = "systemCount")Integer systemCount,
                      @Param(value = "personCount")Integer personCount,@Param(value = "memberCode")Integer memberCode);
    //充值记录
    @Insert("insert into recharacterinfo (username,payContext,payNum,rechargeContext,DATA)value(#{userName},#{payContext},#{payNum},#{rechargeContext},now())")
    int addRechargeInfo(@Param(value = "userName")String userName,@Param(value = "payContext")String payContext,
                        @Param(value = "payNum")Double payNum,@Param(value = "rechargeContext")String rechargeContext);
//PC端注册用户
    @Insert("insert into user(userName,userPassword,data) values(#{userName},#{userPassword},now())")
    int addUser(@Param(value = "userName")String userName,@Param(value = "userPassword")String userPassword );
//PC端查询用户是否被注册
    @Select("select * from user where userName=#{userName} limit 1")
    user SeletctByuserName(@Param(value = "userName") String userName);
//PC端登录
    @Select("select * from user where userName=#{userName} and userPassword=#{userPassword}")
    user SelectUser(@Param(value = "userName")String userName,@Param(value = "userPassword")String userPassword);
//PC端修改密码
    @Update("update user set userPassword=#{userPassword} where userName=#{userName}")
    int upUser(@Param(value = "userName")String userName,@Param(value = "userPassword")String userPassword);
//APP端登录
    @Select("select * from user where userName=#{userName} and userPassword=#{password}")
    user selectUser(@Param(value ="userName" ) String userName, @Param(value = "password") String password);
    //添加垃圾信息
    @Insert("insert into message (connect,code,data) value(#{connect},#{code},now())")
    int addmess(@Param(value = "connect") String connect,@Param(value = "code")String code);
    //查询垃圾信息
    @Select("select code from message where connect=#{connect} ORDER BY data desc LIMIT 1")
    String Select(@Param(value = "connect") String connect);
    //删除垃圾
    @Delete("delete from message")
    int de();
    @Delete("delete from message where connect=#{connect}")
    int delByconnect(String connect);
    //查询该用户是否是会员
    @Select("select * from memberuser where userName=#{userName}limit 1 ")
    memberuser us(@Param(value = "userName")String userName);
    //如果是会员修改指定会员的开通日期
    @Update("update memberuser set data=now() where userName=#{userName} and memberCode=#{memberCode}")
    int upmemberuserData(@Param(value = "userName")String userName,@Param(value = "memberCode") Integer memberCode);
    //如果该用户是会员
    @Update("update memberuser set systemCount=systemCount+ifnull(#{systemCount},0),personCount=personCount+ifnull(#{personCount},0), data=now(), memberCode=#{memberCode} where userName=#{userName}")
    int upMemberUser(@Param(value = "systemCount")Integer systemCount, @Param(value = "personCount") Integer personCount,
                     @Param(value = "memberCode")Integer memberCode,@Param(value = "userName")String userName);
    //开通VIP通过VIPcode查询商品价格商品类型
    @Select("select vipMoney,vipType from member where vipCode=#{vipCode}")
    member moneyByVipCode(@Param(value = "vipCode") Integer vipCode);
    //一次性服务通过产品code查新商品金额
    @Select("select serverMoney from serverinfo where serverCode=#{serverCode}")
    Integer moneyByServerCode(@Param(value = "serverCode") Integer serverCode);
    //如果是会员重新开通更新memberUser的开通时间;
    @Update("update memberuser set data=now() where userName=#{userName}")
    int updateMemberUserData(@Param(value = "userName")String userName);
    //通过产品code获取系统次数和人工次数
    @Select("select systemNum,personNum from member where vipCode=#{vipCode} ")
    member mb(@Param(value = "vipCode") Integer vipCode);
    //查询会员信息
    @Select("select * from memberuser where userName=#{userName}ORDER BY data DESC ")
    List<memberuser> listMemberuser(@Param(value = "userName")String userName);
    //查询 会员充值记录
    @Select("select * from recharacterinfo where userName=#{userName} ORDER BY data DESC")
     List<recharacterinfo> selByrecharacterinfo(@Param(value = "userName")String userName);
    //查询 会员充值记录数量
    @Select("select count(*) from recharacterinfo where userName=#{userName} ORDER BY data DESC")
    int  selByrecharacterinfoCount(@Param(value = "userName")String userName);
   //查询该用户的系统数量或者系统数量是否大于0
    @Select("select sum(systemCount-systemUseNum)systemCount from memberuser where userName=#{userName} ")
    memberuser meSleect(@Param(value = "userName")String userName);
    //查询该用户的人工数量或者系统数量是否大于0
    @Select("select sum(personCount-personUseNum)personCount from memberuser where userName=#{userName} ")
    memberuser meSleectPerson(@Param(value = "userName")String userName);
    //通过产品id获取产品服务类型
    @Select("select serverType from serverinfo where serverCode =#{serverCode} ")
     serverInfo selectServerInfo(@Param(value = "serverCode") Integer serverCode);
    //查询该用户会员类型返回实体类
    @Select("select * from memberuser where userName=#{userName}")
    List<memberuser> meSelectByUsername(@Param(value = "userName")String userName);
    //查询当前会员的所有日期用来扣除会员使用次数
    @Select("select data from memberuser where userName=#{userName} order by data asc")
    List<String> SelectBydata(@Param(value = "userName")String userName);
    //通过时间获取系统次数
    @Select("select (systemCount-systemUseNum) num from memberuser where userName=#{userName} and data=#{data}")
    int systemCount(@Param(value = "userName")String userName,@Param(value = "data")String data);
    //通过时间获取人工次数
    @Select("select (personCount-personUseNum) num from memberuser where userName=#{userName} and data=#{data}")
    int personCount(@Param(value = "userName")String userName,@Param(value = "data")String data);
    //修改系统使用次数
    @Update("update memberuser set systemUseNum=systemUseNum+1 where userName=#{userName} and data=#{data}")
    int updateSystem(@Param(value = "userName")String userName,@Param(value = "data")String data);
    //修改人工使用次数
    @Update("update memberuser set personUseNum=personUseNum+1 where userName=#{userName} and data=#{data}")
    int updatePerson(@Param(value = "userName")String userName,@Param(value = "data")String data);
    //添加司法鉴定信息
    @Insert("insert into elisor (name,phone,userName,email,context,data,imgId) values(#{name},#{phone},#{userName},#{email},#{context},now(),#{imgId})")
    int addElisor(@Param(value = "name")String name,@Param(value = "phone") String phone,@Param(value = "userName")String userName,@Param( value = "email")String email,@Param(value = "context")String context,@Param(value = "imgId")Integer imgId);
    //添加商品ID信息表  为了查询该商品支付是否成功
    @Insert("insert into goodsinfo(goodsId,result,data) values(#{goodsId},#{result},now())")
    int addGoods(@Param(value = "goodsId")String goodsId,@Param(value = "result")String result);
    //修改该产品的结果
    @Update("update goodsinfo set result=#{result} where goodsId=#{goodsId}")
    int upGoods(@Param(value = "result")String result,@Param(value = "goodsId")String goodsId);
    //查询该商品id的结果得到支付情况
    @Select("select result from goodsinfo where goodsId=#{goodsId} order by data desc limit 1")
    String selectResult(@Param(value = "goodsId")String goodsId);
    //查询专家鉴定该用户的最后一张的图片地址，鉴定结果，时间,是否有鉴定记录
    @Select("select imgDetil,imgResult, date ,imgAddress,imgCard from imginfo where userName=#{userName} and  imgType   LIKE '%专家%'  order by date desc limit 1")
    imgInfo SelectByifo(@Param(value = "userName")String userName);
    //查看该用户鉴定的图片存不存在
    @Select("select * from imginfo where userName=#{userName} and imgName=#{imgName} order by date desc ")
    imgInfo SelectimgInfo(@Param(value = "userName")String userName,@Param(value = "imgName")String imgName);
    //修改当前用户鉴定的图片记录
    @Update("update imginfo set imgDetil=#{imgDetil},imgResult=#{imgResult},payMoney=#{payMoney},payType=#{payType} where userName=#{userName},and imgName=#{imgName}")
    int updateImgInfo(@Param(value = "imgDetil")String imgDetil,@Param(value = "imgResult")String imgResult,
                      @Param(value = "payMoney")double payMoney,@Param(value = "payType")String payType,
                      @Param(value = "userName")String userName,@Param(value = "imgName")String imgName);
    //查询司法用户信息表
    @Select("select * from elisor where userName=#{userName}and imgId=#{imgId}")
    elisor selectElisor(@Param(value = "userName")String userName,@Param(value = "imgId") Integer imgId);
}
